package com.etong.frame.directive.checker.impl;

import java.util.Collection;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Length extends Size {

	boolean checkLength(Object[] array) {
		return sizer.check(array.length);
	}

	public boolean build(String expr) {
		clear();

		setName(expr);

		Pattern pattern = Pattern.compile("\\@Length\\((.*)\\)");
		Matcher matcher = pattern.matcher(expr);
		if (matcher.matches()) {
			buildAttribute(expr);
		}

		return DEFAULT != min || DEFAULT != max;
	}

	public boolean check(Object object) {
		if (object instanceof Collection) {
			return checkLength((Object[]) object);
		}
		return false;
	}

}
